/ Assembly List / LJCNetCommon / NetCommon / XmlSerialize

Namespace - LJCNetCommon


Parameters
type - The object type.
data - The object reference.
namespaces - The XML namespaces.
fileSpec - The output file spec.
rootName - The Root Name value.

Syntax

C#
public static Void XmlSerialize(Type type, Object data, XmlSerializerNamespaces namespaces, String fileSpec, String rootName = null)

Serialize an object to an XML message file. (E)

Example

C#
using LJCNetCommon
        
public class Person
{
    public long Id { get; set; }
    public string Name { get; set; }
    public bool PrincipleFlag { get; set; }
}
        
// Serialize an object to an XML message file.
private static void XmlSerialize()
{
    // Setup
    var person = new Person()
    {
        Id = 2,
        Name = "Text",
        PrincipleFlag = true
    };
    string file = "Text.xml";

    // Serialize an object to an XML message file.
    NetCommon.XmlSerialize(person.GetType(), person, null, file);

    // Check the object.
    Person newPerson;
    newPerson = NetCommon.XmlDeserialize(typeof(Person), file) as Person;
}

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.